/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/11/25
* File: EnnSingleton.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#ifndef EnnSingleton_h__
#define EnnSingleton_h__

namespace Enn
{
	template <typename T> class Singleton
	{
	private:
		Singleton(const Singleton<T>&);
		Singleton& operator=(const Singleton<T>&);

	protected:
		static T* _singleton;

	public:
		Singleton()
		{
			ENN_ASSERT(_singleton);
			_singleton = static_cast<T*>(this);
		}

		~Singleton()
		{
			ENN_ASSERT(_singleton);
			_singleton = 0;
		}

		static T& getSingleton()
		{
			ENN_ASSERT(_singleton);
			return *_singleton;
		}

		static T* getSingletonPtr()
		{
			ENN_ASSERT(_singleton);
			return _singleton;
		}
	};
}
#endif    /* EnnSingleton_h__ */